home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / SICL / data1.cab / sicl32 / c / samples / misc / gpiomeas.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-02  |  1.3 KB  |  52 lines

  1. /* gpiomeas.c 
  2.    This program does the following: 
  3.    - Creates a GPIO session with timeout and error checking
  4.    - Signals the device with a CTL0 pulse
  5.    - Reads the device's response using formatted I/O
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <sicl.h>
  10.  
  11. main()
  12. {
  13.    INST id;       /* interface session id */
  14.    float result;  /* data from device */
  15.  
  16.    #if defined (__BORLANDC__) && !defined (__WIN32__)
  17.       _InitEasyWin();  /* required for Borland EasyWin programs */
  18.    #endif
  19.  
  20.    /* log message and exit program on error */
  21.    ionerror(I_ERROR_EXIT);
  22.  
  23.    /* open GPIO interface session, with 3-second timeout */
  24.    id = iopen("gpio");
  25.    itimeout(id, 3000);
  26.  
  27.    /* setup formatted I/O configuration */
  28.    igpiosetwidth(id, 8);
  29.    igpioctrl(id, I_GPIO_READ_EOI, '\n');
  30.  
  31.    /* monitor the device's PSTS line */
  32.    igpioctrl(id, I_GPIO_CHK_PSTS, 1);
  33.  
  34.    /* signal the device to take a measurement */
  35.    itrigger(id);
  36.  
  37.    /* get the data */
  38.    iscanf(id, "%f%*t", &result);
  39.    printf("Result = %f\n", result);
  40.  
  41.    /* close session */
  42.    iclose (id);
  43.  
  44.    /* For Windows 3.1, call _siclcleanup before exiting to release
  45.       resources allocated by SICL for this application.  This call
  46.       is a no-op for WIN32 applications.
  47.    */
  48.    _siclcleanup();
  49.  
  50.    return 0;
  51. }
  52.